// 测试代码
object Main extends App {
  def addOne(list: List[Int]): List[Int] = {
    list.map(x => x + 1)
  }

  def filterEven(list: List[Int]): List[Int] = {
    list.filter(x => x % 2 == 0)
  }
  def mapReduce(
      numbers: List[Int],
      mapFunc: Int => Int,
      reduceFunc: (Int, Int) => Int
  ): Int = {
    val mapped = numbers.map(mapFunc)
    mapped.reduce(reduceFunc)
  }
  val numbers = List(1, 2, 3, 4, 5)
  println(s"Original list: $numbers")
  println(s"After addOne: ${addOne(numbers)}")

  println(s"Even numbers: ${filterEven(numbers)}")

  val sumOfSquares = mapReduce(
    numbers,
    mapFunc = x => x * x,
    reduceFunc = (x, y) => x + y
  )
  println(
    s"Sum of squares: $sumOfSquares"
  )
}
